package com.jie.enums;

import lombok.Data;

import java.util.Arrays;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * 文章流程转换
 * @Author: 杰
 * @Project :net-disk
 * @DateTime: 2024/5/29 16:04
 **/
public enum ArticleFlowStateEnum {
    CREATED(1,"创建帖子"),//创建
    DESENSITIZATION(2,"信息脱敏"), //信息脱敏
    COMPLETED(3,"审核帖子"), //审核
    COMPLETED_SUCCESS(4,"帖子审核成功"),
    //发布帖子
    PUBLISHED(5,"发布帖子");

    private final Integer value;
    private final String desc;
    private static final Map<Integer,ArticleFlowStateEnum> valueMap=(Map) Arrays.stream(values()).collect(Collectors.toMap(ArticleFlowStateEnum::getValue, Function.identity()));

    ArticleFlowStateEnum(Integer value, String desc) {
        this.value = value;
        this.desc = desc;
    }

    public Integer getValue() {
        return value;
    }

    public String getDesc() {
        return desc;
    }
    public static ArticleFlowStateEnum fromValue(Integer value) {
        return (ArticleFlowStateEnum) Optional.ofNullable(valueMap.get(value)).orElseThrow(() -> {
            return new RuntimeException("can not find the enum for this value: " + value);
        });
    }
}

